<template>
	<view class="container">
		<navBar class="s_navBar" isBack backColor="#fff" background="transprant">
			<view class="s_nCenter" slot="center">
				<view class="s_nBg"><image :src="storeInfo.back_img"></image></view>
				<view class="s_nInput">
					<view class="s_nIcon iconfont icon-search" style="color: #fff;"></view>
					<input confirm-type="search" type="text" v-model="keyword" @confirm="searchData" placeholder="搜索您感兴趣的小区" placeholder-style=" #939393;" />
				</view>
			</view>
		</navBar>
		<view class="nar-bar">
			<!-- 导航栏 -->
			<view class="tabs">
				<u-tabs
				name="cate_name" 
				count="cate_count" 
				:list="list" 
				:is-scroll="false" 
				:current="current" 
				@change="change"
				bg-color="rgba(0,0,0,0)"
				active-color="#fff" 
				inactive-color="#606266"
				bar-width="60"></u-tabs>
			</view>			
		</view>
		<template v-if="orderList.length">
			<view class="contentBigBox">
				<view class="content" v-for="(item,index) in orderList" :key="index" v-show="statusNav==item.status">
					<view class="detail">
						<view class="detail-content">
							<view v-if="item.is_back==1" class="is_back">已回退</view>
							<view class="designers">
								<view class="columnName flex">
									<view class="names flex">
										<text>{{item.designer_name}}</text>
										<i class="iconfont icon-more"></i>
									</view>
									<view class="orderStatus">
										{{order_status[item.status]}}
									</view>
								</view>
							</view>
							<!-- <view class="product df-bt">
								<view class="product-info df-ct">
									<image :src="item.headimg.path" mode="" class="product-img"></image>
									<view class="name">
										<view class="name-top">{{item.realname}}</view>
										<view class="phone">{{item.phone}}</view>
									</view>
								</view>
								<view class="iconfont icon-dadianhua" @click="toTelPhone(item.phone)"></view>						
							</view> -->
							<!-- <view class="top df-bt" v-if="item.status==1 || item.status==2">
								<view class="left">
									<view class="t">下单时间</view>
									<view>{{item.create_time | dateformat('YYYY-MM-DD HH:mm:ss')}}</view>
								</view>
								<view class="right">
									<view class="tr">订单编号</view>
									<view>{{item.order_no}}</view>
								</view>
							</view> -->
							<view class="top" >
								<view class="size df-bt">
									<view class="">
										<view class="t">户型</view>
										<view>{{item.house_type}}</view>
									</view>
									<view class="">
										<view class="t">面积</view>
										<view>{{item.house_area}}m²</view>
									</view>
									<view class="right">
										<view class="t">小区</view>
										<view>{{item.estate}}</view>
									</view>
								</view>
								<view class="time df-bt">
									<view class="left">
										<view class="tr" style="text-align: left;">订单编号</view>
										<view>{{item.order_no}}</view>
									</view>
									<view class="right">
										<view class="t" style="text-align: left;">下单时间</view>
										<view>{{item.create_time | dateformat('YYYY-MM-DD HH:mm:ss')}}</view>
									</view>
								</view>
								<!-- <view class="time df-bt" style="margin-top: 40rpx;" v-if="item.status==3 || item.status==4">
									<view class="left">
										<view class="t">开始时间</view>
										<view>{{item.create_time | dateformat('YYYY-MM-DD HH:mm:ss')}}</view>
									</view>
									<view class="right">
										<view class="tr">完成时间</view>
										<view>{{item.order_no}}</view>
									</view>
								</view> -->
								
							</view>
							<view class="commission flex" > 
							<view class="side-left flex">
							  <image :src="`${baseimg}/static/mall/commission_icon.png`"></image>
								<text>佣金</text>
							</view>
							<view class="side-right">
								￥{{item.steward_commission || 0}}
							</view>
							</view>
							<view class="btn-box clearfix">	
							<template  v-if="item.status==1">
								<view class="btn flex" style="justify-content:space-between;">
									<text class="all-price">合同金额 ¥ {{item.contract_price}} </text>
									<text class="btn-text" @tap="handleDetail(item.id)">查看详情</text>
								</view>
							</template>
							<template v-if="item.status==2">
								<view class="btn">
									<text class="all-price">合同金额 ¥ {{item.contract_price}} </text>
									<text class="btn-text" @tap="handleDetail(item.id)">查看详情</text>
								</view>	
								<u-modal v-model="show2" :content="sentContent" show-cancel-button="true"></u-modal>
							</template>
							<template v-if="item.status==3">
								<view class="price-box">
									<text class="all-price">合同金额 ¥ {{item.contract_price}} </text>
									<!-- <text class="d-price" v-if="item.is_many_way==1">待付定金 ¥{{item.deposit_price}}</text> -->
								</view>
								<view class="btn">
									<text class="btn-text" @tap="handleDetail(item.id)">查看详情</text>
								</view>				
							</template>
							<template v-if="item.status==4">
								<view class="price-box">
									<text class="all-price">合同金额 ¥ {{item.contract_price}} </text>
								</view>
								<!-- <view class="price-box" v-if="item.is_many_way==1">
									<text class="all-price">已付定金 ¥ {{item.deposit_price}} </text>
									<text class="d-price">待付尾款 ¥{{item.balance_price}}</text>
								</view> -->
								<view class="btn">
									<text class="btn-text" @tap="handleDetail(item.id)">查看详情</text>
									<!-- <text class="btn-text active" @tap="handleSure(item.id)">确定完成</text> -->
								</view>	
								<!-- <u-modal v-model="show3" :content="sureContent" show-cancel-button="true"></u-modal> -->
							</template>
							<template v-if="item.status==5">
								<view class="price-box">
									<text class="all-price">合同金额 ¥ {{item.contract_price}} </text>
								</view>
								<!-- <view class="price-box" v-if="item.is_many_way==1">
									<text class="all-price">已付定金 ¥ {{item.deposit_price}} </text>
									<text class="d-price">已付尾款 ¥{{item.balance_price}}</text>
								</view> -->
								<view class="btn">
									<text class="btn-text" @tap="handleDetail(item.id)">查看详情</text>
									<!-- <text class="btn-text active">修改信息</text> -->
								</view>				
							</template>
							<template v-if="item.status==0">
								<view class="price-box">
									<text class="all-price">合同金额 ¥ {{item.contract_price}} </text>
									<!-- <text class="d-price" v-if="item.is_many_way==1">待付定金 ¥ {{item.deposit_price}}</text> -->
								</view>
								<view class="btn">
									<text class="btn-text" @tap="handleDetail(item.id)">查看详情</text>
									<u-modal v-model="show4" :content="deleteContent" show-cancel-button="true"></u-modal>
								</view>
								
							</template>
							<u-modal v-model="show" :content="content" @confirm="cancelOrder" show-cancel-button="true"></u-modal>
							</view>
						</view>				
					</view>
				</view>	
				<u-loadmore :status="status" :icon-type="iconType" :load-text="loadText" />
			</view>
			
		</template>
		
		<template v-else>
			<!-- 空空如也 -->
			<view class="notList">
				<image :src="`${baseimg}/static/constr/notList.png`" mode=""></image>
				空空如也
			</view>	
		</template>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				status: 'loadmore',
				iconType: 'flower',
				loadText: {
					loadmore: '轻轻上拉',
					loading: '努力加载中',
					nomore: '实在没有了~'
				},
				list: [
						{
							cate_name: '待接单'
						}, {
							cate_name: '待处理'
						}, {
							cate_name: '待确定',
						},
						{
							cate_name: '待设计'
						}, {
							cate_name: '已完成'
						}, {
							cate_name: '已关闭',
						},
					],
					order_status: {
						0: "已取消",
						1: "待接单",
						2: "待处理",
						3: "待付定金",
						4: "待设计",
						5: "已完成"
					},
				current: 0,
				statusNav:1,
				baseimg:this.$static,
				content:'确定要关闭此订单吗',
				sentContent:'确定发送给客户吗',
				// sureContent:'确定完成吗',
				deleteContent:'确定删除吗',
				show:false,
				show2:false,
				// show3:false,
				show4:false,
				orderList:[],
				page:1,
				pagesize:10,
				keyword:'',
				order_id:null, //订单id
				moduleType:uni.getStorageSync('moduleType'), //超级管家类型 1-超级管家，2-超级政委，3-超级精英
			};
		},
		onLoad(options) {
			console.log(options)
			this.statusNav = options.status?options.status:1
			this.current = options.status?options.status-1:0
			this.getOrderList()
		},
		onShow() {
			
		},
		onReachBottom() {
				this.page++
				this.status = 'loading'
				let sid = this.$store.state.index.sid
				let params = {
					designer_id : sid,
					keyword : this.keyword,
					status : this.statusNav,
					page : this.page,
					pagesize : this.pagesize,
				}
				
				this.$api.getDesignerOrderList(params).then(res=>{
					console.log(res,'订单列表o')
					if(res.code == 1){
						if(!res.data.length){
							this.status = 'nomore'
						}else{
							this.status = 'loading'
						}
						this.orderList = this.orderList.concat(res.data)
					}
				})
		},
		methods:{
			// 获取订单列表
			getOrderList(){
				this.page = 1
				uni.showLoading({
					title:'加载中...'
				})
				let params = {
					keyword : this.keyword,
					status : this.statusNav,
					page : this.page,
					pagesize : this.pagesize,
				}
				this.$api.getDesignerOrderList(params).then(res=>{
					console.log(res,'订单列表o')
					if(res.code == 1){
						if(res.data.length<10){
							this.status = 'nomore'
						}
						this.orderList = res.data					
					}
				})
				uni.hideLoading()
			},
			
			// 搜索
			searchData(){
				this.getOrderList()
			},
			
			toBack() {
			  	uni.navigateBack({
			  	    delta: 1
			  	});
			},
			change(index) {
				console.log(index,6)
				this.current = index;
				if(index==5){
					this.statusNav = 0
				}else{
					this.statusNav = index+1
				}
				this.getOrderList()
			},
			 handleOrder(event){
				 uni.navigateTo({
				 	url:'receOrder?id='+event
				 })
				//  this.$api.designerOrder_accept({id:event}).then(res=>{
				// 	 if(res.code==1){
				// 		 this.getOrderList()
				// 		 uni.navigateTo({
				// 		 	url:`/pageTwo/home/order/order?id=${event}`
				// 		 })
				// 		 uni.showToast({
				// 		 	title:'接单成功',
				// 			icon:'success'
				// 		 })
				// 	 }else{
				// 		 uni.showToast({
				// 		 	title:res.msg,
				// 			icon:'none'
				// 		 })
				// 	 }				 
				//  })
			 },
			 
			 // 电话按钮
			 toTelPhone(phone){
				uni.makePhoneCall({
				 	// 手机号
				    phoneNumber: phone, 
					// 成功回调
					success: (res) => {
						console.log('调用成功!')	
					},
					// 失败回调
					fail: (res) => {
						console.log('调用失败!')
					}
				  });
			 },
			 
			 // 待接单中的关闭订单
			 handleModal(id){
				 this.order_id = id
				 this.show = true
			 },
			 // 待处理中的关闭订单
			 handleSend(id){
				 this.order_id = id
				 this.show = true
			 },
			 // 待付定金中的关闭订单
			 handleAmend(id){
				 this.order_id = id
				 this.show = true
			 },
			 // 关闭订单弹框中确定按钮
			 cancelOrder(){
				this.$api.designerOrder_cancel({id:this.order_id}).then(res=>{
					if(res.code==1){
						uni.showToast({
							title:'关闭成功',
							icon:'success'
						})
						this.getOrderList()
						
					}else{
						uni.showToast({
							title:res.msg,
							icon:'none'
						})
					}
				}) 
			 },
			 handleSure(event){
				 let params = {
					 id:event
				 }
				 this.$api.designerOrder_complete(params).then(res=>{
					 if(res.code==1){
						alert('订单已完成')
					 }
				 })
				 
			 },
			 handleDelete(event){
				 // this.show4 = true
				 uni.showModal({
				 	content:'确定删除此订单吗？',
					success:res=>{
						if(res.confirm){
							let params = {
								id:event
							}
							this.$api.designerOrder_del(params).then(res=>{
								if(res.code==1){
									uni.showToast({
										title:'删除成功',
										icon:'success'
									})
									this.getOrderList()
								}
							})
						}
					}
				 })
			 },
			 
			 // 处理订单
			 handleDispose(event){
				let id = event
				 uni.navigateTo({
				 	url:`/pageTwo/home/order/dispose?id=${id}`
				 })
			 },
			 // 待付定金详情
			 handleDetail(event){
				 let id = event				 
				 uni.navigateTo({
				 	url:`/pages_superHK/pages/order/designer/details?id=${id}`
				 })
			 },
			 // 待设计详情
			 handleDelivery(event){
				  let id = event
				 uni.navigateTo({
				 	url:`/pageTwo/home/order/delivery?id=${id}`
				 })
			 },
			 // 已完成详情
			 handleAccomplish(event){
				 let id = event
				 uni.navigateTo({
				 	url:`/pageTwo/home/order/accomplish?id=${id}`
				 })
			 },
			 // 已关闭详情
			 hanldeClose(event){
				 let id = event
				 uni.navigateTo({
				 	url:`/pageTwo/home/order/close?id=${id}`
				 })
			 },
		}
	}
</script>

<style lang="less" scoped>
	.container{
	   height: 100%;
	   padding-top: 280rpx;
	   // 导航栏
	   .s_navBar {position: absolute;top: 0;left: 0; z-index: 10;
	   	.s_nCenter {width: 100%;}
	   	.s_nBg {width: 100vw;background: rgba(255,255,255,0.1);position: fixed;top: 0;left: 0;z-index: -1;filter: blur(1px);}
	   	.s_nInput {color: #939393;width: 400rpx;height: 66rpx;border: 2rpx solid rgba(255,255,255,0.5); background: rgba(255,255,255,0.1);padding: 0 64rpx;border-radius: 36rpx;position: relative;
	   		& > input {height: 100%;font-size: 24rpx;}
	   	}
	   	.s_nIcon {width: 28rpx;height: 28rpx;line-height: 28rpx;color: #939393;font-size: 28rpx;position: absolute;top: 50%;left: 28rpx;margin-top: -14rpx;}
	   }
	.nar-bar{
		position: fixed;
		left: 0;
		top: 0;
		z-index: 1;
		height: 270rpx;
		width: 100%;
		// position: relative;
		background: url(https://manager.ryz1620.com/static/home-personal/personal-bg.png) no-repeat top;
		.icon-fanhui{
			color: #fff;
			font-size: 38rpx;
			margin-right: 35rpx;
		}
		.search-box {
			width: 100%;
			display: flex;
			align-items: center;
			padding: 0 28rpx;
			padding-top: 50rpx;
		}
		.search{
			display: flex;
			align-items: center;
			justify-content: space-between;
			width: 422rpx;
			height: 66rpx;
			border: 1px solid #FFFFFF;
			opacity: 0.5;
			// background: rgba(52,58,66,.5);
			border-radius: 34rpx;
			input{
				width: 82%;
				height: 100%;
				color: #FFFFFF;
			}
			.icon-sousuo{
				color: #FFFFFF;
				margin-left: 28rpx;
				
			}
		}
		.tabs{
			width: 100%;
			position: absolute;
			left: 0;
			bottom: 10rpx;
			// margin-top: 55rpx;
		}
	}
	.contentBigBox{
		margin-bottom: 40rpx;
		padding-bottom: constant(safe-area-inset-bottom);		padding-bottom: env(safe-area-inset-bottom);
	}
	.content{
		// padding: 40rpx 24rpx;
		.detail{
			padding: 40rpx 24rpx;
			.detail-content{
				position: relative;
				border-radius: 16rpx;
				background-color: #fff;
				padding: 30rpx 24rpx;
				// margin-bottom: 22rpx;
				
				.is_back{
					position: absolute;
					top: 0;
					right: 0;
					width: 90rpx;
					height: 36rpx;
					background-color: #E7AD14;
					border-radius: 0 16rpx 0 16rpx;
					font: 400 22rpx/36rpx PingFang SC;
					text-align: center;
					color: #fff;
				}
				.top{
					padding: 28rpx;
					background: #F8F8F8;
					border-radius: 8rpx;
					color: #505050;
					margin-bottom:10rpx;
					.size{
						margin-bottom: 40rpx;
					}
					.right{
						display: flex;
						flex-direction: column;
						justify-content: flex-end;
						text-align: right;
						// align-items: right;
						}
						.t {
							font-size: 22rpx;
							font-family: PingFang SC;
							font-weight: 400;
							line-height: 36rpx;
							color: #A0A0A0;
						}
						.tr{
							font-size: 22rpx;
							font-family: PingFang SC;
							font-weight: 400;
							line-height: 36rpx;
							color: #A0A0A0;
							text-align: right;
						}
					
					
				}
				.product {
					padding-bottom: 30rpx;
					// padding-top: 22rpx;
					.product-img {
						width: 84rpx;
						height: 84rpx;
						border-radius: 50%;
						margin-right: 20rpx;
					}
					.name{
						.name-top{
							font-size: 26rpx;
							font-weight: 500;
							line-height: 40rpx;
							color: #0A0605;
						}
						.phone{
							font-size: 26rpx;
							font-weight: 400;
							line-height: 40rpx;
							color: #505050;
						}
					}
					.iconfont{
						font-size: 50rpx;
					}
					
				}
				.commission{
					padding:28rpx;
					align-items: center;
					justify-content: space-between;
					.side-left{
						align-items: center;
						image{
							width: 30rpx;
							height: 32rpx;
						}
						text{
							color: #3B3B3B;
							text-indent: 10rpx;
						}
					}
					.side-right{
						color: #DDA955;
					}
				}
				.btn-box {
					&:after { display: block; clear: both; content: ''; visibility: hidden; height: 0; }
					.more {
						float: left;
						font-size: 26rpx;
						font-family: PingFang SC;
						font-weight: 400;
						line-height: 40rpx;
						color: #A0A0A0;
						padding-top: 10rpx;
					}
					.price-box {
						text-align: right;
						padding: 40rpx 0 22rpx 0;
						font-size: 26rpx;
						font-family: PingFang SC;
						font-weight: 500;
						line-height: 20rpx;
						color: #878787;
						.d-price {
							color: #dfb368;
							font-size: 32rpx;
							padding-left: 20rpx;
						}
					}
					.all-price{
						margin-right:20rpx;
					}
					.btn {
						// width: 50%;
						// float: right;
						display: flex;
						justify-content:flex-end ;
						align-items: center;
						.btn-text {
							width: 172rpx;
							height: 64rpx;
							background: #FFFFFF;
							border: 2rpx solid #505050;
							opacity: 1;
							border-radius: 32rpx;
							text-align: center;
							line-height: 64rpx;
							color: #505050;
							font-size: 26rpx;
							margin: 0 10rpx;
						}
						.active{
							background-color: #DBA954;
							color: #fff;
							border: 0;
						}
					}
					
				}
				.designers{
					.columnName{
						align-items: center;
						justify-content: space-between;
						.names{
							color: #252525;
							font-weight: 500;
						}
					}
				}
			}
		}
	}
	
	// 没有数据
	.notList{
		position: absolute;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		margin: auto;
		height: 400rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		width: 426rpx;
		image{
			width: 426rpx;
			height: 356rpx;
			margin-bottom: 40rpx;
		}
		font:500 40rpx/56rpx PingFang SC;
		color: #333;
	}
	.flex{
		display: flex;
	}
}
</style>
